package com.wswy.wzcx.ui.hold;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.thoughtbot.expandablerecyclerview.viewholders.ChildViewHolder;
import com.wswy.wzcx.R;
import com.wswy.wzcx.model.GenreChild;
import com.wswy.wzcx.ui.other.ChildClickListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * Created by wangduheng26 on 2018/1/23.
 * wangduheng26@gmail.com
 */

public class ArtistViewHolder extends ChildViewHolder implements View.OnClickListener {
    private TextView tvContent;
    private SimpleDateFormat dateformat1 = new SimpleDateFormat("MM-dd HH:mm", Locale.CHINA);

    private TextView tvAction;
    private TextView tvDesc;
    public ImageView imageView;
    private ChildClickListener onClickListener;

    public ArtistViewHolder(View itemView) {
        super(itemView);
        tvContent = itemView.findViewById(R.id.tv_content);

        tvAction = itemView.findViewById(R.id.tv_action);
        tvDesc = itemView.findViewById(R.id.tv_desc);
        imageView = itemView.findViewById(R.id.icon);
        itemView.setOnClickListener(this);

    }

    public void bind(GenreChild child) {
        final Context context = tvContent.getContext();
        itemView.setTag(child);
        tvContent.setText(context.getString(R.string.amount_args, child.content));
        tvAction.setText(child.title);
        try {
            Date parse = dateformat1.parse(child.expensesDate);
            String format = dateformat1.format(parse);
            tvDesc.setText(TextUtils.concat(format, " ", child.desc));
        } catch (Exception e) {
            //e.printStackTrace();
            tvDesc.setText(TextUtils.concat(child.expensesDate, " ", child.desc));

        }
    }

    public void setOnClickListener(ChildClickListener onClickListener) {
        this.onClickListener = onClickListener;
    }

    @Override
    public void onClick(View v) {
        final Object tag = v.getTag();
        if (onClickListener != null && tag instanceof GenreChild) {
            onClickListener.onClick(v, (GenreChild) tag);
        }
    }
}
